#ifndef __MCS__IF_ELEMENT__HPP
#define __MCS__IF_ELEMENT__HPP

#include "Element.hpp"
#include "ElifBranchList.hpp"

class IfElement : public Element
{
public:
	IfElement(SourceLocation const & location, ptr<ElifBranch> thenBranch, ptr<ElifBranchList> elifList, ptr<Element> elseBranch)
		: Element(location)
		, thenBranch_(thenBranch)
		, elifList_(elifList)
		, elseBranch_(elseBranch)
	{
	}

	virtual void init(Block * parentBlock)
	{
		Element::init(parentBlock);
		thenBranch_->init(parentBlock);
		elifList_->init(parentBlock);
		elseBranch_->init(parentBlock);
	}

	virtual void execute() const
	{
		if(!thenBranch_->execute())
		{
			if(!elifList_->execute())
			{
				elseBranch_->execute();
			}
		}
	}
private:
	ptr<ElifBranch> thenBranch_;
	ptr<ElifBranchList> elifList_;
	ptr<Element> elseBranch_;
};

#endif //__MCS__IF_ELEMENT__HPP
